<?php
/**
 * Object/Avenant.php
 */

namespace RHX\Model\Object;

use Zend\Db\Adapter\Adapter;

class Avenant {

    public $id;
    public $site;
    public $hebdo;
    public $taux;
    public $debut;
    public $fin;
    public $poste_id;
    public $niveau;
    public $echelon;
    public $college;
    public $libelle;
    public $avenant_file;
    protected $adapter;

    /**
     * Constructeur
     *
     * @param \Zend\Db\Adapter\Adapter $adapter
     * @param array $data
     */
    public function __construct(Adapter $adapter, $data = array()) {
	$this->exchangeArray($data);
	$this->adapter = $adapter;
    }

    public function exchangeArray($data) {
	$this->id	 = isset($data['id']) ? $data['id'] : null;
	$this->site	 = isset($data['site']) ? (int)$data['site'] : null;
	$this->hebdo	 = isset($data['hebdo']) ? $data['hebdo'] : 0.0;
	$this->taux	 = isset($data['taux']) ? $data['taux'] : 0.0;
	$this->debut	 = isset($data['debut']) ? $data['debut'] : '0000-00-00';
	$this->fin	 = isset($data['fin']) ? $data['fin'] : '0000-00-00';
	$this->poste_id	 = isset($data['poste_id']) ? $data['poste_id'] : 0;
	$this->niveau	 = isset($data['niveau']) ? (int) $data['niveau'] : 1;
	$this->echelon	 = isset($data['echelon']) ? (int) $data['echelon'] : 1;
	$this->college	 = isset($data['college']) ? (int) $data['college'] : 1;
        $this->libelle	 = isset($data['libelle']) ?  $data['libelle'] : '';
        $this->avenant_file	 = isset($data['avenant_file']) ? $data['avenant_file'] : '';
    }

    public function getArrayCopy() {
	return get_object_vars($this);
    }

    /**
     * Poste
     * 
     * @return Poste
     */
    public function getPoste() {
	// Table Poste
	$posteTable = new \RHX\Model\Table\PosteTable($this->adapter);

	return $posteTable->get($this->poste_id);
    }

    /**
     * Collège
     * 
     * @return College
     */
    public function getCollege() {
	$collegeTable = new \RHX\Model\Table\CollegeTable($this->adapter);

	return $collegeTable->get($this->college);
    }
    
    /**
     * Site
     * 
     * @return Site
     */
    public function getSite(){
	$siteTable = new \RHX\Model\Table\SiteTable($this->adapter);
	
	return $siteTable->get($this->site);
    }
    
    /* teste si l'objet Avenant instancié est l'Avenant en cours de l'employé propriétaire
     * 
     * @return boolean
     */
    public function isAvenantInitiale(){
        $employeTable = new \RHX\Model\Table\EmployeTable($this->adapter);
        $employe = $employeTable->getOneByAvenant($this->id);        
        $avenantInit = $employe->getAvenantInitial();            
        
        return  ($this->id == $avenantInit->id) ; 
    }

}

